home *** CD-ROM | disk | FTP | other *** search
- Path: news.lpr.carel.fi!usenet
- From: Ari Lukumies <aril@cmt.lpr.mail.carel.fi>
- Newsgroups: comp.lang.c
- Subject: Re: Initialising structure members - help please!
- Date: Tue, 20 Feb 1996 11:05:53 +0200
- Organization: Carelcomp Forest
- Message-ID: <31298EF1.5F2C@cmt.lpr.mail.carel.fi>
- References: <4gb8hn$3m8@news.mistral.co.uk>
- NNTP-Posting-Host: renoir.cclahti.carel.fi
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 2.0b6a (WinNT; I)
-
- Mike Barnard wrote:
- >
- > Hi all.
- >
- > I'm a learner. I am trying to create a function to display a list of
- > menu items using a doubly linked list. My problem is in initialising
- > the members of the individual menu items.
- >
- > Within a function called VPCMENU.C I have created a structure...
- >
- > // Define a structure to hold the menu item information.
- >
- > struct menuitem
- > {
- > int number; // Item 1, item 2 etc.
- > char description[70]; // Room for a text description
- > struct menuitem *next; // Pointer to next menu item
- > struct menuitem *last; // Pointer to last menu item
- > };
- >
- > Now I create 5 instances of variables of the type menuitem...
- >
- > // Define the instances of the structure.
- >
- > struct menuitem one,two,three,four,five;
- >
- > Now, the fun (not) bit. I tried to initialise the items with...
- >
- > one.number = 1;
- > one.description = "1. Calculate a minefield";
- > one.next = two;
- > one.last = five;
- >
- > The first one passes OK, but the second one creates an error. As it
- > stands it says "Lvalue required". Help says "The left side of an
- > assignment operator must be an addressable expression." I don't know
- > about the third and fourth ones. Yet.
-
- Since you declared 'description' as an array of chars, use strcpy(one.description,
- "whatever string"); Be sure you won't use longer strings than the space available. A
- better approach would be to declare 'decription' as a 'char *' and then malloc
- enough space for whatever string you're going to place into it. (Also, your syntax
- would work in that case.) The last two will work if you add & in front of them.
-
- >
- > This is an almost exact copy of the structure examples in my book.
- > (The beginners guide to C by Wrox). Page 387 for those who have it.
- >
- > So, can anyone help please? (I must get snippets!). This is for a PC
- > in text mode using Borland C++ 3.0. The completed program is to do
- > calculations for the e-mail game VGA Planets.
- >
- > Thanks.
- >
-
- You're welcome,
- AriL
- --
- All my opinions are mine and mine alone.
-